package ITA.MQproject;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;

public class TestPtpCustomer {

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		ConnectionFactory factory=new ActiveMQConnectionFactory("tcp://10.222.29.152:61616");
		Destination queueDestination=new ActiveMQQueue("angers");
		Connection connection =factory.createConnection();
		connection.start();
		
//		Session session=connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
//		MessageConsumer mc=session.createConsumer(queueDestination);
//		
//		TextMessage msg=(TextMessage) mc.receive();
//		System.out.println(msg.toString());
		
		Session session=connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
		MessageConsumer mc=session.createConsumer(queueDestination);
		TextMessage msg=(TextMessage) mc.receive();
		System.out.println(msg.getText());
		
//		TextMessage msg1=(TextMessage) mc.receive();
//		System.out.println(msg1.toString());
//		session.commit();
		msg.acknowledge();  //用户自确认模式下的确认收到消息
//		Message message=null;
		connection.close();
		session.close();
	}

}
